""" pyhotp unit test

"""

import unittest
import pyhotp

class TestStandardValue(unittest.TestCase):
    """ from RFC4226
    """
    def test_sha1(self):  
        secret = "12345678901234567890"
        digit = 6
        standardvalue = { 0:755224, 1:287082, 2:359152, 3:969429, 4:338314,
                          5:254676, 6:287922, 7:162583, 8:399871, 9:520489
                        }
        
        myotp = pyhotp.HOTP("sha1", secret, digit)
        for counter in standardvalue.keys():
            self.assertTrue(myotp.generateOTP(counter) == standardvalue[counter],
                    "Error count is %d ." % counter)
     

class TestInitHOTP(unittest.TestCase):
    
    def test_hashalg(self):
        # Support the following Hash algorithm: 
        #       MD5, SHA1, SHA256, SHA384, SHA512
        
        # sha1 is default algorithm 
        myotp = pyhotp.HOTP()
        self.assertTrue(myotp.hashname == "sha1")
        
        support_hashalg = ("md5", "MD5","sha1", "SHA1","sha256", "SHA256",
            "sha384", "SHA384","sha512", "SHA512")
            
        for alg in support_hashalg:
            myotp = pyhotp.HOTP(alg)
            self.assertTrue(myotp.hashname == alg.lower(),
                "Not support alg : %s" % alg)
        
        
        try:
            notsupport_hashalg = "sha32"
            myotp = pyhotp.HOTP(notsupport_hashalg)
        except ValueError:
            self.assertTrue(notsupport_hashalg not in support_hashalg)
            
    def test_counter(self):
        
        try:
            for counter in (2, 3, 6, 7, 8, 9):
                myotp = pyhotp.HOTP("sha1", "12345678901234567890", counter)
        except ValueError:
            self.assertTrue(counter not in (6, 7, 8))
       
           
     
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
            
            
